import request from '@/utils/request'

// 查询社区帖子列表
export function listCommunityPost(query, pageReq) {
  return request({
    url: '/community/post/list',
    method: 'post',
    data: query,
    params: pageReq
  })
}

// 查询社区帖子详细
export function getCommunityPost(id) {
  return request({
    url: '/community/post/' + id,
    method: 'get'
  })
}

// 新增社区帖子
export function addCommunityPost(data) {
  return request({
    url: '/community/post',
    method: 'post',
    data: data
  })
}

// 修改社区帖子
export function updateCommunityPost(data) {
  return request({
    url: '/community/post',
    method: 'put',
    data: data
  })
}

// 删除社区帖子
export function delCommunityPost(id) {
  return request({
    url: '/community/post/' + id,
    method: 'delete'
  })
}

// 导出社区帖子
export function exportCommunityPost(query) {
  return request({
    url: '/community/post/export',
    method: 'get',
    params: query
  })
}

// 根据话题ID查询帖子列表
export function getPostsByTopicId(topicId, pageReq) {
  return request({
    url: '/community/post/topic/' + topicId,
    method: 'get',
    params: pageReq
  })
}

// 获取热门帖子
export function getHotPosts(limit = 10) {
  return request({
    url: '/community/post/hot',
    method: 'get',
    params: { limit }
  })
}

// 搜索帖子
export function searchPosts(keyword, pageReq) {
  return request({
    url: '/community/post/search',
    method: 'get',
    params: { keyword, ...pageReq }
  })
}

// 批量更新帖子状态
export function batchUpdatePostStatus(data) {
  return request({
    url: '/community/post/batch/status',
    method: 'put',
    data: data
  })
}

// 置顶帖子
export function pinPost(id) {
  return request({
    url: '/community/post/' + id + '/pin',
    method: 'put'
  })
}

// 取消置顶帖子
export function unpinPost(id) {
  return request({
    url: '/community/post/' + id + '/unpin',
    method: 'put'
  })
}

// 获取帖子统计信息
export function getPostStatistics(id) {
  return request({
    url: '/community/post/' + id + '/statistics',
    method: 'get'
  })
}

// 审核帖子
export function auditPost(id, status, reason) {
  return request({
    url: '/community/post/' + id + '/audit',
    method: 'put',
    data: { status, reason }
  })
}